package com.station.administrators.controller;


import com.open.capacity.common.entity.RegionModel;
import com.open.capacity.common.web.Result;
import com.station.administrators.fegin.RegionFegin;
import com.open.capacity.common.model.StationModel;
import com.station.administrators.service.StationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author YangGang
 * @Title: 工位管理
 * @Description: TODO
 * @date 2021/6/25/9:58
 */
@Api(tags = "工位管理")
@RestController
@RequestMapping("/station")
public class StationController {
    @Autowired
    private StationService stationService;
    @Autowired
    private RegionFegin regionFegin;

    @ApiOperation("添加工位")
    @PostMapping("/add")
    public Object add(StationModel station){
        stationService.add(station);
        return Result.succeed("添加成功！");
    }
    @ApiOperation("修改工位")
    @PostMapping("/update")
    public Object update(StationModel station){
        stationService.update(station);
        return Result.succeed("修改成功！");
    }
    @ApiOperation("删除工位")
    @PostMapping("/delete/{id}")
    public Object delete(@PathVariable Long id){
        stationService.delete(id);
        return Result.succeed("删除成功！");
    }
    @ApiOperation("根据id查询工位")
    @GetMapping("/findById")
    public Object findById(Long id){
        StationModel station=stationService.findById(id);
        return Result.succeed(station,"");
    }
    @ApiOperation("查询工位")
    @GetMapping("/findAll")
    public Object findAll(StationModel station){
        List<StationModel> stationList=stationService.findAll(station);
        Integer count=stationService.getCount(station);
        Map<String,Object> map=new HashMap<>();
        map.put("stationList",stationList);
        map.put("count",count);
        return Result.succeed(map,"");
    }
    @ApiOperation("修改工位状态")
    @PostMapping("/updateStatus")
    public Object updateStatus(StationModel station){
        stationService.updateStatus(station);
        return Result.succeed("状态修改成功！");
    }

    /**
     * 添加工位是得到地址信息
     * @return
     */
    @ApiOperation("添加工位时得到地址信息")
    @GetMapping("/getAddress")
    public Object getAddress(){
        Object province = regionFegin.findProvince();
        return Result.succeed(province,"");
    }

    /**
     * 根据省份id得到区域
     * @param regionModel
     * @return
     */
    @ApiOperation("根据省份id得到区域")
    @GetMapping("/findLow")
    public Object findLow(RegionModel regionModel){
        Object low = regionFegin.findLow(regionModel);
        return Result.succeed(low,"");
    }

}
